import 'package:flutter/material.dart';
import 'package:flutterdemo01/demo56/Login.dart';

main(){
  // runApp(DrawApp());
  runApp(DrawApp2());
}

class DrawApp extends StatefulWidget {
  const DrawApp({Key? key}) : super(key: key);

  @override
  _DrawAppState createState() => _DrawAppState();
}

class _DrawAppState extends State<DrawApp> with SingleTickerProviderStateMixin{



  var drawDatas= [

    {
      'title':'我的空间',
      'icon':Icon(Icons.person),
    },  {
      'title':'用户中心',
      'icon':Icon(Icons.verified_user),
    },  {
      'title':'我的设置',
      'icon':Icon(Icons.settings),
    },

  ];


  TabController? _tabController;

  void initState() {
    _tabController = new TabController(length: _tabs.length, vsync: this);
  }


  List<Tab> _tabs = [
    Tab(text: '明教',),
    Tab(text: '霸道',),
    Tab(text: '天策',),
    Tab(text: '纯阳',),
    Tab(text: '少林',),
    Tab(text: '长健',),
    Tab(text: '七秀',),
    Tab(text: '五毒',),
    Tab(text: '天门',),
    Tab(text: '唐门',),
    Tab(text: '武当',),
    Tab(text: '昆仑',),
  ];

  var _drawDatas= [

    {
      'title':'我的空间',
      'icon':Icon(Icons.person),
    },  {
      'title':'用户中心',
      'icon':Icon(Icons.verified_user),
    },  {
      'title':'我的设置',
      'icon':Icon(Icons.settings),
    },

  ];


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(

        appBar: AppBar(
          title: Row(
            children: [
              Expanded(child: TabBar(
                controller: _tabController,
                tabs: _tabs,
                isScrollable: true,
                indicatorColor: Colors.teal,
              ))
            ],
          ),
        ),
        drawer: Container(
          width: 200,
          child: Drawer(
            child: Column(
              children: [

               Row(
                 children: [
                   Expanded(child: DrawerHeader(
                     child: Text('北凉王', style: TextStyle(fontSize: 20, color: Colors.white),),
                     decoration: BoxDecoration(
                         image: DecorationImage(image: NetworkImage('https://www.itying.com/images/flutter/1.png'),fit: BoxFit.cover)
                     ),),)
                 ],
               ),

                Column(

                  children: drawDatas.map((Map e) => ListTile(
                    leading: e['icon'],
                    title: Text(e['title']),)).toList(),

                )
              ],
            ),
          ),

        ),
        body: TabBarView(
          controller: _tabController,
          children: _tabs.map((e) => Center(child: Text(e.text??"其他"),)).toList(),
        ),
      ),
    );
  }

}


class DrawApp2 extends StatefulWidget {
  const DrawApp2({Key? key}) : super(key: key);

  @override
  _DrawApp2State createState() => _DrawApp2State();
}

class _DrawApp2State extends State<DrawApp2>  {


  List<Tab> _tabs = [
    Tab(text: '明教',),
    Tab(text: '霸道',),
    Tab(text: '天策',),
    Tab(text: '纯阳',),
    Tab(text: '少林',),
    Tab(text: '长健',),
    Tab(text: '七秀',),
    Tab(text: '五毒',),
    Tab(text: '天门',),
    Tab(text: '唐门',),
    Tab(text: '武当',),
    Tab(text: '昆仑',),
  ];

  var _drawDatas= [

    {
      'title':'我的空间',
      'icon':Icon(Icons.person),
    },  {
      'title':'用户中心',
      'icon':Icon(Icons.verified_user),
    },  {
      'title':'我的设置',
      'icon':Icon(Icons.settings),
    },

  ];



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyView(),
    );
  }
}


class MyView extends StatefulWidget {
  const MyView({Key? key}) : super(key: key);

  @override
  _MyViewState createState() => _MyViewState();
}

class _MyViewState extends State<MyView> with SingleTickerProviderStateMixin{

  TabController? _controller;

  void initState() {
    _controller = new TabController(length: _tabs.length, vsync: this);
  }

  List<Tab> _tabs = [
    Tab(text: '明教',),
    Tab(text: '霸道',),
    Tab(text: '天策',),
    Tab(text: '纯阳',),
    Tab(text: '少林',),
    Tab(text: '长健',),
    Tab(text: '七秀',),
    Tab(text: '五毒',),
    Tab(text: '天门',),
    Tab(text: '唐门',),
    Tab(text: '武当',),
    Tab(text: '昆仑',),
  ];

  var _drawDatas= [

    {
      'title':'我的空间',
      'icon':Icon(Icons.person),
    },  {
      'title':'用户中心',
      'icon':Icon(Icons.verified_user),
    },  {
      'title':'我的设置',
      'icon':Icon(Icons.settings),
    },

  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          children: [
            Expanded(child: TabBar(
              controller: _controller,
              tabs: _tabs,
              isScrollable: true,
              indicatorColor: Colors.yellow,
            ))
          ],
        ),
      ),
      drawer: Drawer(
        child: Column(
          children: [

            Row(
              children: [
                // Expanded(child:  DrawerHeader(
                //   child: Text('hhhhh',
                //     style: TextStyle(color: Colors.white),
                //
                //   ),
                //   decoration: BoxDecoration(
                //       image: DecorationImage(
                //           image: NetworkImage('https://www.itying.com/images/flutter/3.png' ), fit: BoxFit.cover
                //       )
                //   ),),),
                Expanded(child: UserAccountsDrawerHeader(
                  accountName: Text('徐晓'),
                  accountEmail: Text('285063749@qq.com'),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: NetworkImage('https://www.itying.com/images/flutter/1.png'),
                  ),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage('https://www.itying.com/images/flutter/7.png'),
                          fit: BoxFit.cover
                      )
                  ),
                ))
              ],
            ),


            Column(children: _drawDatas.map((Map e) => ListTile(
              leading: e['icon'],
              title: Text(e['title']),
              onTap: () {

                Navigator.of(context).pop();
                Navigator.push(context, MaterialPageRoute(builder:(context) { return Login();}));

              },
            )).toList()),
          ],
        ),
      ),
      body: TabBarView(
        controller: _controller,
        children: _tabs.map((e) => Text(e.text??'其他')).toList(),
      ),

    );
  }
}


